<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>promise.race</title>
</head>
<body>
<script type="text/javascript">
let time=0
let isOver=false
function showTime(){
	console.log(time)
	++time
	if(!isOver)setTimeout(showTime,990)
}
function getNumber(num,second){
	return new Promise((resolve, reject)=>{
		let n=parseInt(Math.random()*19)+num-9
		if(n<=num)setTimeout(resolve,second*1000,n)
		else reject({n:n,msg:'数值应该小于'+num})
	})
}
showTime()
let p1=getNumber(100, 7);
let p2=getNumber(200, 4);
let p3=getNumber(300, 5);
Promise.race([p1,p2,p3]).then(r=>{
	console.log(r)
	console.log(r+" * "+r+" = "+(r*r))
}).catch(r=>{
	console.log(r.n , r.msg)
}).finally(()=>{
	isOver=true
})
</script>
</body>
</html>